/* eslint-disable vue/no-v-html */
<template>
  <div class="dynamic">
    <div class="dynamic-content-head">
      <nuxt-link to="/moment">
        <div
          class="dynamic-content-head-text"
        >
          动态
        </div>
      </nuxt-link>

      <div class="dynamic-content-head-icon" />
      <div class="dynamic-content-head-detils-text">
        动态详情
      </div>
    </div>
    <div class="dynamic-wrap">
      <div class="dynamic-content">
        <div class="dynamic-content-box">
          <div class="dynamic-user-wrap">
            <div
              class="dynamic-user-photo"
              :style="{background: `url('${dynamicData.user ? dynamicData.user.user_photo : ''}') center center no-repeat`,backgroundSize:'100% 100%'}"
            />
            <div class="dynamic-user-content">
              <div class="dynamic-user-name">
                {{ dynamicData.user.user_name }}
              </div>
              <div class="dynamic-user-information">
                <div class="dynamic-user-time">
                  发表于：{{ times(dynamicData.created_at) }}
                </div>
              </div>
            </div>
          </div>
          <Product
            v-if="dynamicData.product!=null"
            :datas="dynamicData"
            :dynamic="true"
          />

          <div class="dynamic-content-text">
            <!-- eslint-disable-next-line vue/no-v-html -->
            <p v-html="text" />
          </div>
          <div v-if="!dynamicData.content.videos.length" class="dynamic-image-wrap">
            <div v-for="item in dynamicData.content.images" :key="item.image_id">
              <img :src="item.thumbnail_url" alt="" class="dynamic-image">
            </div>
          </div>
          <div v-else class="video-wrap">
            <video controls autoplay name="media">
              <source :src="mp4_play" type="video/mp4">
            </video>
          </div>
        </div>
      </div>
      <div class="dynamic-recommend">
        <div class="dynamic-recommend-header">
          <div class="dynamic-recommend-header-left">
            相关推荐
          </div>
          <div class="dynamic-recommend-header-right">
            <nuxt-link to="/moment">
              <div class="dynamic-recommend-header-right-text">
                更多
              </div>
            </nuxt-link>
            <div class="dynamic-recommend-header-right-icon" />
          </div>
        </div>
        <div class="dynamic-recommend-content">
          <div
            v-for="item in dynamicRecommendData"
            :key="item.content_id"
            class="dynamic-recommend-item"
          >
            <div v-if="item.content_type==='article'">
              <nuxt-link :to="`/article/${item.content_id}`">
                <div
                  class="dynamic-recommend-item-photo"
                  :style="{background: `url('${item.content.images.length?item.content.images[0].thumbnail_url:'' }') center center no-repeat`,backgroundSize:'cover'}"
                />
              </nuxt-link>
              <div class="dynamic-recommend-item-content">
                <nuxt-link :to="`/article/${item.content_id}`">
                  <div
                    class="dynamic-recommend-item-content-title"
                  >
                    {{ item.content.article_title }}
                  </div>
                </nuxt-link>

                <div class="dynamic-recommend-item-content-user">
                  <div class="dynamic-recommend-item-content-user-left">
                    <div
                      class="dynamic-recomment-item-content-user-photo"
                      :style="{background: `url('${item.user.user_photo }') center center no-repeat`,backgroundSize:'100% 100%'}"
                    />
                    <div class="dynamic-recomment-item-content-user-name">
                      {{ item.user.user_name }}
                    </div>
                  </div>
                  <div class="dynamic-recommend-item-content-user-right">
                    <div class="dynamic-recommend-item-content-user-right-icon" />
                    <div class="dynamic-recommend-item-content-user-right-help">
                      {{ item.star_count }}
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <div v-else>
              <nuxt-link :to="`/moment/${item.content_id}`">
                <div
                  class="dynamic-recommend-item-photo"
                  :style="{background: `url('${item.content.images.length?item.content.images[0].thumbnail_url:item.content.videos[0].preview_cover_url }') center center no-repeat`,backgroundSize:'cover'}"
                />
              </nuxt-link>

              <div class="dynamic-recommend-item-content">
                <nuxt-link :to="`/moment/${item.content_id}`">
                  <div
                    class="dynamic-recommend-item-content-title"
                  >
                    <p> {{ item.content.moment_content }}</p>
                  </div>
                </nuxt-link>
                <div class="dynamic-recommend-item-content-user">
                  <div class="dynamic-recommend-item-content-user-left">
                    <div
                      class="dynamic-recomment-item-content-user-photo"
                      :style="{background: `url('${item.user.user_photo }') center center no-repeat`,backgroundSize:'100% 100%'}"
                    />
                    <div class="dynamic-recomment-item-content-user-name">
                      {{ item.user.user_name }}
                    </div>
                  </div>
                  <div class="dynamic-recommend-item-content-user-right">
                    <div class="dynamic-recommend-item-content-user-right-icon" />
                    <div class="dynamic-recommend-item-content-user-right-help">
                      {{ item.star_count }}
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { times } from '@/utils/util'
import Product from '@/components/product'
export default {
  components: {
    Product
  },
  props: {
    dynamicData: {
      type: Object,
      default: () => { }
    },
    dynamicRecommendData: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      times,
      text: '',
      description: '',
      keyWrods: '',
      mp4_play: ''
    }
  },
  created() {
    this.text = this.dynamicData.content.moment_content.replace(/\n/gm, '<br/>')
    // title处理
    if (this.dynamicData.content.moment_content) {
      this.title = this.dynamicData.content.moment_content.slice(0, 21)
      // description 处理
      this.description = this.dynamicData.content.moment_content.slice(0, 80)
    } else {
      this.title = this.dynamicData.user.user_name + '的动态'
      this.description = ''
    }
    // keyWrods处理
    this.dynamicData.topic ? this.dynamicData.topic.map(item => {
      this.keyWrods += item.topic_name + ','
    }) : this.keyWrods = ''
    if (this.dynamicData.content.videos.length) {
      if (this.dynamicData.content.videos[0].play_url.substr(-3, 3) === 'mp4') {
        this.mp4_play = this.dynamicData.content.videos[0].play_url
      } else {
        this.mp4_play = this.dynamicData.content.videos[0].mp4_play_url
      }
    }
  },
  head() {
    return {
      title: `${this.title}_容猫医美`,
      meta: [
        { hid: 'description',
          name: 'description',
          content: `${this.description}`
        }, {
          name: 'keywords', content: ''
        }
      ]
    }
  }
}
</script>
<style scoped lang="scss">
.dynamic {
  width: 100%;
  background: rgba(246, 246, 246, 1);
  .dynamic-wrap {
    width: 1190px;
    margin: 0 auto;
    padding-bottom: 30px;
    overflow: hidden;
    display: flex;
  }
}
.dynamic-content-head {
  width: 1190px;
  height: 54px;
  display: flex;
  align-items: center;
  margin: 0 auto;
  padding-top: 8px;
}
.dynamic-content-head-text {
  font-size: 14px;
  font-weight: 400;
  color: rgba(51, 51, 51, 1);
  line-height: 20px;
  margin-left: 30px;
}
.dynamic-content-head-text:hover {
  cursor: pointer;
}
.dynamic-content-head-detils-text {
  font-size: 14px;
  font-weight: 400;
  color: rgba(80, 76, 255, 1);
  line-height: 20px;
}
.dynamic-content-head-icon {
  width: 4px;
  height: 8px;
  background: url("~assets/img/right-icon.png") center center no-repeat;
  background-size: 100% 100%;
  margin-left: 10px;
  margin-right: 10px;
}
.dynamic-content {
  width: 840px;
  background: rgba(255, 255, 255, 1);
  border-radius: 4px;
  .dynamic-content-box {
    padding: 0 30px;
    .dynamic-user-wrap {
      width: 100%;
      margin-top: 10px;
      margin-bottom: 21px;
      display: flex;
      .dynamic-user-photo {
        width: 36px;
        height: 36px;
        border-radius: 50%;
      }
      .dynamic-user-content {
        margin-left: 6px;
        .dynamic-user-name {
          font-size: 14px;
          font-weight: 500;
          color: rgba(102, 102, 102, 1);
          line-height: 10px;
        }
      }
      .dynamic-user-information {
        margin-top: 10px;
        display: flex;
      }
      .dynamic-user-time {
        font-size: 11px;
        font-weight: 400;
        color: rgba(153, 153, 153, 1);
        line-height: 16px;
      }
    }
    .dynamic-content-text{
      font-size:16px;
      font-family:PingFangSC-Regular,PingFang SC;
      font-weight:400;
      color:rgba(51,51,51,1);
      margin-top: 10px;
    }
    .dynamic-image-wrap{
      width: 100%;
      margin-top: 21px;
    }
    .video-wrap{
      width: 100%;
      margin-top: 21px;
      >video{
        width: 100%;
      }
    }
  }
}
.dynamic-recommend {
  width: 340px;
  height: 1147px;
  background: rgba(255, 255, 255, 1);
  border-radius: 4px;
  margin-left: 10px;
  .dynamic-recommend-header {
    width: 100%;
    height: 44px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-right: 10px;
    border-bottom: 1px solid rgba(246, 246, 246, 1);
    .dynamic-recommend-header-left {
      font-size: 14px;
      font-weight: 600;
      color: rgba(51, 51, 51, 1);
      line-height: 20px;
      margin-left: 10px;
    }
    .dynamic-recommend-header-right {
      font-size: 14px;
      font-weight: 600;
      color: rgba(216, 216, 216, 1);
      line-height: 20px;
      margin-right: 10px;
      display: flex;
      align-items: center;
      .dynamic-recommend-header-right-icon {
        width: 8px;
        height: 8px;
        background: url("~assets/img/more-icon.png") center center no-repeat;
        background-size: 100% 100%;
        margin-left: 4px;
      }
    }
  }
}
.dynamic-recommend-content {
  width: 100%;
}
.dynamic-recommend-item {
  margin-top: 10px;
  padding: 0 10px 10px;
  border-bottom: 1px solid rgba(246, 246, 246, 1);
  .dynamic-recommend-item-photo {
    width: 320px;
    height: 187px;
  }
  .dynamic-recommend-item-photo:hover {
    cursor: pointer;
  }
  .dynamic-recommend-item-content-title {
    width: 100%;
    font-size: 14px;
    font-weight: 400;
    color: rgba(51, 51, 51, 1);
    line-height: 20px;
    margin-top: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
  }
  .dynamic-recommend-item-content-title:hover {
    cursor: pointer;
  }
  .dynamic-recommend-item-content-user {
    display: flex;
    justify-content: space-between;
    .dynamic-recommend-item-content-user-left {
      display: flex;
      align-items: center;
      margin-top: 10px;
      .dynamic-recomment-item-content-user-photo {
        width: 26px;
        height: 26px;
        border-radius: 50%;
      }
      .dynamic-recomment-item-content-user-name {
        margin-left: 10px;
        font-size: 14px;
        font-weight: 400;
        color: rgba(153, 153, 153, 1);
        line-height: 20px;
      }
    }
    .dynamic-recommend-item-content-user-right {
      display: flex;
      align-items: center;
      .dynamic-recommend-item-content-user-right-icon {
        width: 16px;
        height: 14px;
        background: url("~assets/img/heart.png") center center no-repeat;
        background-size: 100% 100%;
      }
      .dynamic-recommend-item-content-user-right-help {
        margin-left: 8px;
        font-size: 14px;
        font-weight: 400;
        color: rgba(153, 153, 153, 1);
        line-height: 20px;
      }
    }
  }
}
</style>
